package testJdk.io.datastream;

import java.io.*;

/**
 * @ClassName : com.io.datastream.TestDataStream
 * @Description : 类描述
 * Created by cyd on 2020-12-10 22:49:40
 */
public class TestDataStream {
    public static void main(String[] args) {
        try {
            TestDataStream.write();
            TestDataStream.read();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    //抛出异常，由方法调用者处理
    public static void write() throws IOException {
        //显示层次关系
        FileOutputStream fos = new FileOutputStream("D:\\readme.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        DataOutputStream dos = new DataOutputStream(bos);
        //写入数据
        dos.writeInt(1);
        dos.writeDouble(3.14);
        dos.writeBoolean(true);
        dos.writeUTF("cyd陈俞大");
        //关闭流
        dos.close();
    }

    public static void read() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\readme.txt");
        BufferedInputStream bis = new BufferedInputStream(fis);
        DataInputStream dis = new DataInputStream(bis);

        System.out.println(dis.readInt());
        System.out.println(dis.readDouble());
        System.out.println(dis.readBoolean());
        System.out.println(dis.readUTF());

        dis.close();

    }
}
